<?php
    include_once '../fn.php';
    loginCheck();
    $flag = 'index';
?>

<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <title>Dashboard &laquo; Admin</title>
  <link rel="stylesheet" href="../assets/vendors/bootstrap/css/bootstrap.css">
  <link rel="stylesheet" href="../assets/vendors/font-awesome/css/font-awesome.css">
  <link rel="stylesheet" href="../assets/vendors/nprogress/nprogress.css">
  <link rel="stylesheet" href="../assets/css/admin.css">
  <script src="../assets/vendors/nprogress/nprogress.js"></script>
</head>
<body>
  <script>NProgress.start()</script>

  <div class="main">
    <nav class="navbar">
      <button class="btn btn-default navbar-btn fa fa-bars"></button>
      <ul class="nav navbar-nav navbar-right">
        <li><a href="profile.html"><i class="fa fa-user"></i>个人中心</a></li>
        <li><a href="login.php"><i class="fa fa-sign-out"></i>退出</a></li>
      </ul>
    </nav>
    <div class="container-fluid">
      <div class="jumbotron text-center">
        <h1>One Belt, One Road</h1>
        <p>Thoughts, stories and ideas.</p>
        <p><a class="btn btn-primary btn-lg" href="post-add.html" role="button">写文章</a></p>
      </div>
      <div class="row">
        <div class="col-md-4">
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title">站点内容统计：</h3>
            </div>
            <?php
              // 动态渲染站点统计

              // 1.构造查询文章串
              $sql_posts_total = 'select count(*) as total from posts';//直接让数据库返回数量，好
              $sql_posts_drafted = 'select * from posts where status="drafted"';

              $posts_total_count = my_query($sql_posts_total)[0]['total'];
              $posts_drafted_count = count(my_query($sql_posts_drafted));


              // 2.构造查询分类串
              $sql_categories_total = 'select * from categories';
              $categories_total_count = count(my_query($sql_categories_total));

              // 3.构造查询评论串
              $sql_comments_total = 'select * from comments';
              $sql_comments_held = 'select * from comments where status="held"';

              $comments_total_count = count(my_query($sql_comments_total));
              $comments_held_count = count(my_query($sql_comments_held));              

              // echo '<pre>';
              // print_r($comments_total_count );
              // echo '</pre>';

              // echo '<pre>';
              // print_r($posts_total_count);
              // echo '</pre>';
            ?>
            <ul class="list-group">
              <li class="list-group-item"><strong><?php echo $posts_total_count; ?></strong>篇文章（<strong><?php echo $posts_drafted_count; ?></strong>篇草稿）</li>
              <li class="list-group-item"><strong><?php echo $categories_total_count; ?></strong>个分类</li>
              <li class="list-group-item"><strong><?php echo $comments_total_count; ?></strong>条评论（<strong><?php echo $comments_held_count; ?></strong>条待审核）</li>
            </ul>
          </div>
        </div>
        <div class="col-md-4"></div>
        <div class="col-md-4"></div>
      </div>
    </div>
  </div>

  <!-- 引入公共侧边栏 -->
  <?php include './inc/aside.php'; ?>

  <script src="../assets/vendors/jquery/jquery.js"></script>
  <script src="../assets/vendors/bootstrap/js/bootstrap.js"></script>
  <script>NProgress.done()</script>
</body>
</html>
